{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 as cv\n",
    "import os\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "dir = 'F:/VOS/ubutu-vm/resources/gannotation/300VW_Dataset_2015_12_14/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['001',\n",
       " '002',\n",
       " '003',\n",
       " '004',\n",
       " '007',\n",
       " '009',\n",
       " '010',\n",
       " '011',\n",
       " '013',\n",
       " '015',\n",
       " '016',\n",
       " '017',\n",
       " '018',\n",
       " '019',\n",
       " '020',\n",
       " '022',\n",
       " '025',\n",
       " '027',\n",
       " '028',\n",
       " '029',\n",
       " '031',\n",
       " '033',\n",
       " '034',\n",
       " '035',\n",
       " '037',\n",
       " '039',\n",
       " '041',\n",
       " '043',\n",
       " '044',\n",
       " '046',\n",
       " '047',\n",
       " '048',\n",
       " '049',\n",
       " '053',\n",
       " '057',\n",
       " '059',\n",
       " '112',\n",
       " '113',\n",
       " '114',\n",
       " '115',\n",
       " '119',\n",
       " '120',\n",
       " '123',\n",
       " '124',\n",
       " '125',\n",
       " '126',\n",
       " '138',\n",
       " '143',\n",
       " '144',\n",
       " '150',\n",
       " '158',\n",
       " '160',\n",
       " '203',\n",
       " '204',\n",
       " '205',\n",
       " '208',\n",
       " '211',\n",
       " '212',\n",
       " '213',\n",
       " '214',\n",
       " '218',\n",
       " '223',\n",
       " '224',\n",
       " '225',\n",
       " '401',\n",
       " '402',\n",
       " '403',\n",
       " '404',\n",
       " '405',\n",
       " '406',\n",
       " '407',\n",
       " '408',\n",
       " '409',\n",
       " '410',\n",
       " '411',\n",
       " '412',\n",
       " '505',\n",
       " '506',\n",
       " '507',\n",
       " '508',\n",
       " '509',\n",
       " '510',\n",
       " '511',\n",
       " '514',\n",
       " '515',\n",
       " '516',\n",
       " '517',\n",
       " '518',\n",
       " '519',\n",
       " '520',\n",
       " '521',\n",
       " '522',\n",
       " '524',\n",
       " '525',\n",
       " '526',\n",
       " '528',\n",
       " '529',\n",
       " '530',\n",
       " '531',\n",
       " '533',\n",
       " '537',\n",
       " '538',\n",
       " '540',\n",
       " '541',\n",
       " '546',\n",
       " '547',\n",
       " '548',\n",
       " '550',\n",
       " '551',\n",
       " '553',\n",
       " '557',\n",
       " '558',\n",
       " '559',\n",
       " '562']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirs = next(os.walk(dir))[1]\n",
    "dirs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 处理 frames\n",
    "for sub_dir in dirs:\n",
    "    capture = cv.VideoCapture(f'{dir}/{sub_dir}/vid.avi')\n",
    "    if not os.path.exists(f'{dir}/{sub_dir}/frames'):\n",
    "        os.mkdir(f'{dir}/{sub_dir}/frames')\n",
    "    nums_file = 1\n",
    "    ret = 1\n",
    "    while ret:\n",
    "        ret, frame = capture.read()\n",
    "        if ret:\n",
    "            filename = str(nums_file)\n",
    "            filename = '0' * (6-len(filename)) + filename\n",
    "            cv.imwrite(f'{dir}/{sub_dir}/frames/{filename}.jpg', frame)\n",
    "        nums_file += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取 pts\n",
    "p = 'F:/VOS/ubutu-vm/resources/gannotation/300VW_Dataset_2015_12_14/001/annot/000001.pts'\n",
    "pts = torch.load(p)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "558e254f4d4aea76686259d096a34338cd93cfb603c5e3feef8d36743459a954"
  },
  "kernelspec": {
   "display_name": "Python 3.6.5 ('gan-edit')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
